package cn.com;

import java.io.BufferedReader;
import java.io.InputStreamReader;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FSDataInputStream;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;

public class HDFSTest {

	public static void main(String[] args) throws Exception {
		// 0. 获取集群配置信息
		Configuration conf = new Configuration();
		// 1. 获取文件系统
		FileSystem fs = FileSystem.get(conf);
		// 2. 获取文件
		Path p = new Path("/input.txt");
		FSDataInputStream in = fs.open(p);
		// 3. 读取文件内容
		InputStreamReader isr = new InputStreamReader(in);
		BufferedReader br = new BufferedReader(isr);

		String str = null;
		while ((str = br.readLine()) != null) {
			System.out.println(str);
		}
		// 2. 创建目录
		// Path path = new Path("/user/zhaoyingfei/test");
		// boolean isSuccess = fs.mkdirs(path);
		// System.out.println(isSuccess);

		// 3. 删除目录
		// fs.removeAcl(path);
		// fs.delete(path, true);
		// 4.关闭流

		fs.close();

	}
}
